//Offer52 - 两个链表的第一个公共节点
class Solution {
    ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int lenA = 0;
        int lenB = 0;
        ListNode a = headA;
        ListNode b = headB;

        while(a!=null){
            a = a.next;
            lenA++;
        }
        while(b!=null){
            b = b.next;
            lenB++;
        }
        int len = lenA - lenB;
        a = headA;
        b = headB;
        if(len < 0){
            len = -len;
            a = headB;
            b = headA;
        }
        while(len != 0){
            a = a.next;
            len--;
        }

        while(a != b){
            a = a.next;
            b = b.next;
        }
        return a;
    }
}
public class Test {
}
